<template>
  <d2-container>
    <div class="pb-2 ml-2">
      <div><el-button type="warning" @click="addarea" icon="el-icon-plus">添加地区</el-button></div>
    </div>
    <div class="flex-1 ml-2">
      <el-table :data="areaList" border stripe>
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" label="序号" type="index" width="65" />
        <el-table-column align="center" label="地区名称" prop="name" width="130" />
        <el-table-column align="center" label="上级地区" prop="parent_name" width="130" />
        <el-table-column align="center" label="地区邮编" prop="adcode" width="70" />
        <el-table-column align="center" label="地区首字母" prop="initial" width="70" />
        <el-table-column align="center" label="是否显示" prop="is_recommend" width="60">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.is_show" active-color="#13ce66" inactive-color="#C4C4C4" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="120">
          <template slot-scope="scope">
            <el-button size="mini" @click="areaEdit(scope.row.id)">修改</el-button>
            <el-button size="mini" type="danger" @click="openDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex-1 mt-3">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page.sync="queryInfo.page" layout="total, prev, pager, next" :total="areaTotal">
        </el-pagination>
      </div>
    </div>
  </d2-container>
</template>

<script>
  import {
    commonareaListUrl
  } from '@/utils/interface'
  export default {
    data() {
      return {
        queryInfo: {
          page: 1,
          pageSize: 10
        },
        areaList:[],
        areaTotal: 1
      }
    },
    created() {
      this.initData()
    },
    methods: {
      initData() {
        this.getAreaList()
      },
      getAreaList() {
        this.$get(commonareaListUrl, this.queryInfo).then(res => {
          this.areaList = res.data.data.list
          this.areaTotal = res.data.data.total
        })
      },
      // 分页页码显示条数
      handleSizeChange(newSize) {
        // 把每页显示多少数据重新赋值
        this.queryInfo.pageSize = newSize
        this.getAreaList()
      },
      // 翻页事件
      handleCurrentChange(newPage) {
        this.queryInfo.page = newPage
        this.getAreaList()
      },
      areaEdit(areaId){

      },
      openDelete(areaId){

      },
      addarea(){

      }
    }
  }
</script>

<style>
</style>
